# 请写一个小游戏，人狗大站;  规则:
#     1   2个角色，人和狗，游戏开始后，生成2个人，3条狗，人狗互相交替对战(注意,人只能打狗,  狗也只会咬人); 
#         人的打击力为10;  初始化血为100;    狗的攻击力为 15; 初始化血为80;
#     2  人被狗咬了会掉血，狗被人打了也掉血，狗和人的攻击力，具备的功能都不一样。血为0的话,表示死亡,退出游戏;
#         人和狗的攻击力,都会因为被咬, 或者被打而降低(人被咬一次,打击力降低2;  狗被打一次,攻击力降低3);
#     3   对战规则: 
#      A  随机决定,谁先开始攻击; 
#      B  一方攻击完毕后, 另外一方再开始攻击;  攻击的目标是随机的(比如, 人要打狗了, 随机找一条血不为0的狗攻击);
#      C  每次攻击, 双方只能安排一个人,或者一条狗进行攻击;
# 提示：注意组织代码的方式；狗类用一个单独的py文件； 人用一个单独的py文件； 在写一个fight模块（也用类来组织；在这个模块中，导入人和狗模块中编写好的方法）

import random, time
from Fwpeople import People
from DogKing import Dog

class Fight( object ):

    persons = []
    dogs = []

    def __init__( self, p1, p2, d1, d2, d3 ):
        self.p1 = p1
        self.p2 = p2
        self.d1 = d1
        self.d2 = d2
        self.d3 = d3
        self.persons.append( p1 )
        self.persons.append( p2 )
        self.dogs.append( d1 )
        self.dogs.append( d2 )
        self.dogs.append( d3 )

    def start( self ):

        order = random.randint( 1, 2 ) #random order

        while True:

            order = order + 1
            # hp <= 0 or atk <= 0, delete the role

            for person in self.persons:
                print( '>>>>>>>>>', end='' )
                print( person.name, ' hp: ', person.hp, ' atk: ', person.atk )
            for dog in self.dogs:
                print( '>>>>>>>>>',end='' )
                print( dog.name, ': ', dog.hp, ' atk: ', dog.atk )

            if len(self.persons) <= 0:
                print( 'All humans die! Game over!' )
                break
            if len(self.dogs) <= 0:
                print( 'All dogs die! Game over!' )
                break

            if order%2 == 0: # people fight

                # random selection
                p_label = random.randint( 0, len(self.persons) - 1 )
                d_label = random.randint( 0, len(self.dogs) - 1 )
                
                # start fighting
                self.persons[p_label].fight( self.dogs[d_label] )
                time.sleep(1)

            elif order % 2 == 1: # dog bite
                
                # random selection
                p_label = random.randint( 0, len(self.persons) - 1 )
                d_label = random.randint( 0, len(self.dogs) - 1 )
                
                # start fighting
                self.dogs[d_label].fight( self.persons[p_label] )
                time.sleep(1)

            for person in self.persons:
                if person.hp <= 0 or person.atk <= 0:
                    self.persons.remove( person )
            for dog in self.dogs:
                if dog.hp <= 0 or dog.atk <= 0:
                    self.dogs.remove( dog )


p1 = People( 'whh' )
p2 = People( 'xjj' )

d1 = Dog( 'gouxinwang1' )
d2 = Dog( 'gouxinwang2' )
d3 = Dog( 'gouxinwang3' )

fight = Fight( p1, p2, d1, d2, d3 )
fight.start()